/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package wrap.core;

import java.net.URL;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.UIManager;

/**
 *
 * @author liang
 */
public class CC {

    private static CController instance = null;
    
    static final String START = "Start";

    static URL url;

    static{
        setUIFont(CConst.FontResource);

        addPageByClassNames(CConst.PAGES);


        boolean b = isValidDateStr("10/49/2009");
        System.out.println(b);
    }

    public static boolean isValidDateStr(String date) {
        String pattern = "MM/dd/yyyy";
        SimpleDateFormat format = new SimpleDateFormat(pattern);
        format.setLenient(false);
        try {
            System.out.println(format.parse(date));
        } catch (ParseException ex) {
            return false;
        }

        return true;
    }


    public static void setUIFont (javax.swing.plaf.FontUIResource f){

        java.util.Enumeration keys = UIManager.getDefaults().keys();
        while (keys.hasMoreElements()) {
            Object key = keys.nextElement();
            Object value = UIManager.get(key);
            if (value instanceof javax.swing.plaf.FontUIResource) {
                UIManager.put(key, f);
            }
        }
    }
    
    static void addPageByClassNames(String[] name){
        if(name == null )
            return;
        
        for(int i = 0; i < name.length; i++){
            addPageByClassName(name[i]);
        }
    }

    static void addPageByClassName(String name){
        java.util.Map pages = getInstance().getPages();
        PageContainer pc = new PageContainer(name);
        pages.put(pc.getName(), pc);
    }

    
    static CController getInstance(){
        if(instance == null){
            instance = new CController();
        }
        return instance;
    }

    // These are static interfaces:
    public static void to(String page){
        getInstance().to(page);
    }

    public static void back(){
        getInstance().back();
    }

    public static void playPageSound(){
        getInstance().playPageSound();
    }

    public static void enableSound(){
        getInstance().enableSound();
    }

    public static void disableSound(){
        getInstance().disableSound();
    }

    public static java.util.HashMap getValues(){
        return getInstance().getValues();
    }

}
